//
//  TimeModel.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/6/11.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class TimeModel: BaseModel {
    var openTime:String = "00:00"
    var endTime:String = "23:59"
    var dateArr:Array<Int> = []
    var dateStr:String = ""
    var timeStr:String = ""
    
    
    /// 修改日期
    func changeDateStr() {
        dateStr = ""
        for i in dateArr {
            switch i {
            case  1:
                dateStr = dateStr + kText("星期一") + "、"
                break
            case  2:
                dateStr = dateStr + kText("星期二") + "、"
                break
            case  3:
                dateStr = dateStr + kText("星期三") + "、"
                break
            case  4:
                dateStr = dateStr + kText("星期四") + "、"
                break
            case  5:
                dateStr = dateStr + kText("星期五") + "、"
                break
            case  6:
                dateStr = dateStr + kText("星期六") + "、"
                break
            case  7:
                dateStr = dateStr + kText("星期日") + "、"
                break
            default:break
                
            }
        }
        if dateStr.count > 1 {
       dateStr  =  (dateStr as NSString).substring(to: dateStr.ch_length-1)
        }
        
    }
    
    func changeTimeStr() {
        timeStr = String(format: "%@ - %@", openTime,endTime)
    }
    
    
    /// 整理网络回调数据
    ///
    /// - Parameter model: 时间model
    func changeDateInfor(model:OpenTimeList) {
//        let arr = (model.loopDate as NSString).components(separatedBy: ",")
        self.openTime = model.openTime
        self.endTime = model.closeTime
        self.changeTimeStr()
        guard let arr = model.loopDate.jsonObject as? [Any] else {
            return
        }
        for dateNumber in arr {
            if ((dateNumber as? Int) != nil) {
                self.dateArr.append(dateNumber as! Int)
            }
        }
        self.changeDateStr()
        
    }
}
